<?php

/**
 * 公共数据库操作模块 Model
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zwt007 $  <zwttmac@qq.com>
 * $Id: table.class.php 89 2011-12-04 13:39:27Z zwt007 $
 * http://www.t-mac.org；
 */
class table extends Model
{

    private $db;

    /**
     * 初始化变量　定义私有变量
     */
    public function _init()
    {
        //连接数据库
        $this->db = $this->connect();
    }

    /**
     * 新增表记录，返回id
     * @param type $table
     * @param type $info
     * @return type 
     */
    public function addTableReturn($table, $info)
    {
        $rs = $this->db->autoInsertReturn($table, $info);
        return $rs;
    }

    /**
     * 新增表记录, 不返回id
     * @param type $table
     * @param type $info
     * @return type 
     */
    public function addTable($table, $info)
    {
        $rs = $this->db->autoExecute($table, $info);
        return $rs;
    }

    /**
     * 更新表
     * @param type $table
     * @param type $info
     * @param type $mode
     * @param type $where
     * @return type 
     */
    public function updateTable($table, $info, $where = '', $mode = 'UPDATE')
    {
        $rs = $this->db->autoExecute($table, $info, $mode, $where);
        return $rs;
    }

    /**
     * 删除表
     * @param type $table
     * @param type $where
     * @return type 
     */
    public function delTable($table, $where)
    {
        $rs = $this->db->execute("DELETE FROM $table WHERE $where");
        return $rs;
    }

    /**
     * 取表的一条记录
     * @param type $table
     * @param type $where
     * @param type $field
     * @return type 
     */
    public function getTableInfo($table, $where, $field='*')
    {
        $rs = $this->db->getRow("SELECT {$field} FROM $table WHERE $where");
        return $rs;
    }
    
    /**
     * 取表的所有记录
     * @param type $table
     * @param type $where
     * @param type $field
     * @return type 
     */
    public function getTableAll($table, $where='1=1', $field='*')
    {
        $rs = $this->db->getAll("SELECT {$field} FROM $table WHERE $where");
        return $rs;
    }

}